//
//  UIBarButtonItem+Button.swift
//  微博08
//
//  Created by 1 on 16/3/6.
//  Copyright © 2016年 cjf. All rights reserved.
//

import UIKit

// 扩展UIBarButtonItem,方便包装带按钮的UIBarButtonItem
extension UIBarButtonItem {
    //在分类里面添加构造函数
    // convenience: 便利构造函数，方便构造对象
    // 便利构造函数必须调用指定构造函数
    // extension 中只能添加便利构造函数
    convenience init(imageName: String) {
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        self.init(customView: button)
    }
    
    /*
    // 包装带按钮的UIBarButtonItem
    // class 可以不用创建对象直接使用类名调用
    class func createBarButtonItem(imageName: String) -> UIBarButtonItem {
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        return UIBarButtonItem(customView: button)
    }
    */
}
